<?php
	header('Content-Type:application/json');  //此声明非常重要
include('connect.php');
	$username = $_POST['username'];
	$password = $_POST['pwd'];
	$sql = "select * from worker where username='{$username}' and userpasswd='{$password}' ";
	$notice =$db->query($sql);
	
	if ($notice->num_rows > 0) {
	    // 输出数据
	    while($row = $notice->fetch_assoc()) {
	        
	        if($row["username"]==$username && $row["userpasswd"]==$password){
	        	 $ret = ["code" => "OK","username" => $username];
				 session_start();
				     //  注册登陆成功的 admin 变量，并赋值 true
				     $_SESSION["admin"] = true;
	        	echo json_encode($ret,JSON_UNESCAPED_UNICODE);  //JSON_UNESCAPED_UNICODE防止中文乱码
	        }else{
	        	 $ret = ["code" => "NO","username" => null];
	        	 echo json_encode($ret,JSON_UNESCAPED_UNICODE);  //JSON_UNESCAPED_UNICODE防止中文乱码
	        }
	    }
	} else {
	    $ret = ["code" => "NO","username" => null];
	    echo json_encode($ret,JSON_UNESCAPED_UNICODE);  //JSON_UNESCAPED_UNICODE防止中文乱码
	}
	
?>